import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';


import 'package:qaun_ni_dev/pages/brushsHappy/brush_video.dart';
import 'package:qaun_ni_dev/utils/date_time.dart';
import 'package:qaun_ni_dev/provider/brush_provider.dart';


class BrushDetail extends StatelessWidget {
  var brushData;
  BrushDetail(this.brushData);

  VideoPlayerController _controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('刷刷乐详情'),
        ),
        body: Stack(
          children: <Widget>[
            _detailContent(context,brushData),
            _optionBtn(context, brushData),
          ],
        ));
  }

  Widget _detailContent(context,brushData) {
    return Container(
        padding: EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 80),
        height: 610,
        child: ListView(
          children: <Widget>[
            Column(
              children: <Widget>[
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('数据ID:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.id}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户昵称:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.userInfo.nickName}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户性别:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
//                        child: Text('${timeStampChange(brushData.createTime)}'),
                        child: Text('${brushData.userInfo.sex == 1 ? '男': '女'}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户状态:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.userInfo.infoStatu == 9 ? '视频审核': '其他状态'}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('账号状态:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.userInfo.accountStatu == 0 ? '正常': '封禁'}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('动态类型:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.userInfo.infoStatu == 0 ? '日常动态': '其他动态'}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('动态内容:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.postContent}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('动态地址:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${brushData.postGeo == ''? '未知地址': brushData.postGeo}'),
                      )
                    ],
                  ),
                ),



                Container(
                  padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))
                  ),
                  child: Column(
                    children: <Widget>[
                      Container(
                        width: 360,
                        child:  Text('用户头像：', textAlign: TextAlign.left,),
                      ),
                      Container(
                        child: Row(
                          children: <Widget>[
                            SizedBox(
                              width: 90,
                            ),
                            Container(
                              width: 180,
                              child: Image.network(brushData.userInfo.avatarUrl),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
//                视频
                Container(
                  padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))
                  ),
                  child: Column(
                    children: <Widget>[
                      Container(
                        width: 360,
                        child:  Text('用户视频：', textAlign: TextAlign.left,),
                      ),
                      Container(
                        child: Row(
                          children: <Widget>[
                            SizedBox(
                              width: 90,
                            ),
                            InkWell(
                              child: Container(
                                width: 180,
                                child: Image.network(brushData.postCoverUrl),
                              ),
                              onTap: () {
                                Navigator.push(context,MaterialPageRoute(
                                  builder: (context) {
                                    Provider.of<BrushProvider>(context,listen: false).getVideoStUrl(brushData.postVideoUrl);
//                                    return BrushVideo(brushData.postVideoUrl);
                                    return BrushVideo();
                                  }
                                ));
                              },
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ],
            )
          ],
        ));
  }

  Widget _optionBtn(context, brushData) {
    return Positioned(
      bottom: 0,
      width: 360,
      height: 80,
      left: 40,
      child: Container(
        alignment: Alignment.center,
        child: Row(
          children: <Widget>[
            Container(
              width: 100,
              height: 40,
              padding: EdgeInsets.only(top: 10, bottom: 10),
              margin: EdgeInsets.only(right: 80),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(40)),
                color: Colors.lightBlue,
              ),
              child: InkWell(
                onTap: () {
                  _agreeActive(context,brushData);
                },
                child: Text(
                  '添加',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            Container(
              width: 100,
              height: 40,
              padding: EdgeInsets.only(top: 10, bottom: 10),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(40)),
                color: Colors.redAccent,
              ),
              child: InkWell(
                onTap: () {
                  _forbidActive(context, brushData);
                },
                child: Text(
                  '屏蔽',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _forbidActive(context, brushData) {
    showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('警告'),
          content: Text('确认设置该tag为屏蔽吗？'),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () {
                Navigator.of(context).pop();
              } , //关闭对话框
            ),
            FlatButton(
              child: Text("确认"),
              onPressed: () {

                Provider.of<BrushProvider>(context,listen: false).setVideoTag(context,brushData.id,'SSN');
                Navigator.of(context).pop(); //关闭对话框
              },
            ),
          ],
        );
      },
    ).then((val) {
      print(val);
    });
  }

  Widget _agreeActive(context, brushData) {
    showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('提示'),
          content: Text('确认设置tag为添加吗？'),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () {
                Navigator.of(context).pop();
              } , //关闭对话框
            ),
            FlatButton(
              child: Text("确认"),
              onPressed: () {
                Provider.of<BrushProvider>(context,listen: false).setVideoTag(context,brushData.id,'SSL');
                Navigator.of(context).pop(); //关闭对话框
              },
            ),
          ],
        );
      },
    ).then((val) {
      print(val);
    });
  }

}
